import actionType from './actionTypes'
import {getNoticicationList} from '../request'
const startMarkHasRead = () => {
    return {
        type: actionType.START_MARK_NOTIFITION_HAS_READ
    }
}

const finishMarkHasRead = () => {
    return {
        type: actionType.FINISH_MARK_NOTIFITION_HAS_READ
    }
}

export const markNotificationById = (id) => {
    return dispath => {
        dispath(startMarkHasRead())
        setTimeout(() => {
            dispath({
                type: actionType.MARK_NOTIFICATION_BY_ID,
                payload: {id}
            })
        dispath(finishMarkHasRead())

        }, 2000)
    }
}

export const markAllNotificationHasRead = () => {
    return dispath =>{
        dispath(startMarkHasRead())
        setTimeout(() => {
            dispath({
                type: actionType.MARK_ALL_NOTIFICATION_BY_HASREAD,
            })
        dispath(finishMarkHasRead())
        }, 2000)
    }
}

export const getNotificationList = () => {
    return dispath =>{
        dispath(startMarkHasRead())
        getNoticicationList().then(res=>{
            dispath({
            type: actionType.GET_NOTIFICATIONLIST,
            payload: {list: res[0].list}
        })
        }).finally(()=>{
            dispath(finishMarkHasRead())
        })
       
    }
}